using System;
using System.IO;
using System.Text.RegularExpressions;

using ObjectRelationalMapping.Helper;
using ObjectRelationalMapping.Model;

namespace ObjectRelationalMapping
{
    internal static partial class Output
    {
        internal static class Class
        {
            internal static void Write ( )
            {
                if ( Common.EntityCollection.Count > 0 )
                {
                    Console.Write ( "Writing the class files..." );
                    int numberOfClassFiles = 0;

                    string fileName;
                    StreamWriter fileWriter;

                    foreach ( Entity entity in Common.EntityCollection )
                    {
                        fileName =
                            Common.ProjectDirectoryForClassObjects
                                + entity.ClassName + ".cs";

                        fileWriter = new StreamWriter ( fileName );
                        fileWriter.WriteLine ( entity.ClassTemplate );
                        fileWriter.Close ();

                        ++numberOfClassFiles;
                    }

                    Console.WriteLine (
                        "and {0} class files were written.",
                        numberOfClassFiles );
                }
            }
        }
    }
}